<template>
  <ele-modal
    :width="950"
    :visible="visible"
    :confirm-loading="loading"
    :title="'申请退款'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    @ok="save"
  >
    <div class="margin-y-15 flex align-center" style="margin-left: 100px">
      <a-image width="40" height="40" />
      <div class="margin-left-15">
        <div>储值卡号：{{ props.editData.value_card_no || '' }}</div>
        <div class="flex align-center margin-top-15">
          <div
            >{{ props.editData.name || '' }}
            <span v-if="props.editData.nickname"
              >({{ props.editData.nickname || '' }})</span
            ></div
          >
          <span class="margin-left-24"
            >手机号：{{ props.editData.mobile || '' }}</span
          >
        </div>
      </div>
    </div>
    <a-form
      :label-col="{ md: { span: 5 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="24" :sm="24" :xs="24">
          <a-form-item label="会员昵称" :colon="false">
            <div>{{ info.nickname || '' }}</div>
          </a-form-item>
          <a-form-item label="会员姓名" :colon="false">
            <div>{{ info.name || '' }}</div>
          </a-form-item>
          <a-form-item label="会员手机" :colon="false">
            <div>{{ info.mobile || '' }}</div>
          </a-form-item>
          <a-form-item label="储值卡号" :colon="false">
            <div>{{ info.value_card_no || '' }}</div>
          </a-form-item>
          <a-form-item label="储值卡金额" :colon="false">
            <div>{{ info.credit || '' }}</div>
          </a-form-item>
          <a-form-item label="可退金额" :colon="false">
            <div>{{ info.credit || '' }}</div>
          </a-form-item>
          <a-form-item
            label="应退金额"
            :colon="false"
            v-bind="validateInfos.refund_amount"
          >
            <a-input
              allow-clear
              placeholder="请输入"
              v-model:value="form.refund_amount"
            />
          </a-form-item>
          <a-form-item label="退款原因" :colon="false">
            <a-textarea
              allow-clear
              placeholder="请输入"
              v-model:value="form.cause"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form, message } from 'ant-design-vue';

  import { salesman_list } from '@/api/order/order/jewelry_order';
  import { get_pay_type_select } from '@/api/setting/pay_type';
  import { get_value_card_detail } from '@/api/order/value_card';
  // 表格列配置
  const useForm = Form.useForm;

  const emit = defineEmits(['done', 'update:visible']);

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
    editData: Object
  });

  // 提交状态
  const loading = ref(false);
  const info = ref({});
  console.log('----', props.editData);
  // 表单数据
  const form = reactive({
    member_id: props.editData.id,
    refund_amount: '',
    cause: ''
  });

  onMounted(() => {
    if (props.editData.id) {
      get_value_card_detail({ member_id: props.editData.id }).then((res) => {
        info.value = res.detail.member;
      });
    }
  });

  // 表单验证规则
  const rules = reactive({
    refund_amount: [
      {
        required: true,
        message: '请输入应退金额',
        type: 'string',
        trigger: 'blur'
      }
    ]
  });

  const { validate, validateInfos } = useForm(form, rules);

  /* 保存*/
  const save = () => {
    validate()
      .then(() => {
        emit('done', form);
      })
      .catch(() => {});
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
